Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory firmware #261

Merged
merged 25 commits into from
Apr 27, 2022
Merged

Inventory firmware #261

merged 25 commits into from
Apr 27, 2022

Conversation

joelrebel
Copy link
Member

  • Checklist
  • Tests added

  • Similar commits squashed

  • What does this PR implement?

    • Defines and implements a InventoryGetter interface for Redfish, Asrockrack
    • Defines and implements a FirmwareInstaller, FirmwareInstallVerifier interfaces
    • Defines and implements a PostCodeGetter interface for Asrockrack
    • Implements the PowerStateGetter, PowerState setter interfaces for Asrockrack
  • The HW vendor this change applies to

    • Asrockrack, Redfish supported hardware
  • The HW model number, product name this change applies to

    • Asrockrack - E3C246D4I-NL
  • What version of tooling - vendor specific or opensource does this change depend on

    • Gofish v0.12.1
  • Description for changelog/release notes

    • Defines and implements a InventoryGetter interface for Redfish, Asrockrack
    • Defines and implements a FirmwareInstaller, FirmwareInstallVerifier interfaces
    • Defines and implements a PostCodeGetter interface for Asrockrack
    • Implements the PowerStateGetter, PowerState setter interfaces for Asrockrack

Copy link
Member

@jacobweinstock jacobweinstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is quite a large PR. Might take me some time to get through.

bmc/inventory.go Outdated Show resolved Hide resolved
@joelrebel
Copy link
Member Author

@jacobweinstock thanks for taking a look at this! let me know when you're done and I can cut a v0.5.3 release.
I have a few more changes that I'll drop into a sub branch, sorry about the size of this PR, I can work on having smaller stacked PRs instead going ahead for related changes.

Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't programmed against many of these BMCs, but have a few suggestions on the PR

bmc/firmware.go Outdated Show resolved Hide resolved
bmc/firmware.go Outdated Show resolved Hide resolved
bmc/inventory.go Outdated Show resolved Hide resolved
bmc/postcode.go Outdated Show resolved Hide resolved
devices/constants.go Show resolved Hide resolved
providers/redfish/firmware.go Outdated Show resolved Hide resolved
providers/redfish/firmware.go Outdated Show resolved Hide resolved
providers/redfish/firmware_test.go Outdated Show resolved Hide resolved
providers/redfish/inventory.go Outdated Show resolved Hide resolved
providers/redfish/inventory.go Outdated Show resolved Hide resolved
@joelrebel
Copy link
Member Author

@micahhausler thanks for the review!

Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup. I have just a few minor suggestions

bmc/firmware.go Outdated Show resolved Hide resolved
// FirmwareInstall uploads and initiates firmware update for the component
func (a *ASRockRack) FirmwareInstall(ctx context.Context, component, applyAt string, forceInstall bool, reader io.Reader) (jobID string, err error) {
var size int64
if file, ok := reader.(*os.File); ok {
Copy link
Contributor

@micahhausler micahhausler Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If length is required, maybe consider a different interface like fs.File or you could declare an interface like

type LengthReader interface {  
    io.Reader
    Len() int
}

which is satisfied by bytes.Buffer and strings.Reader and provide a helper for os.File/fs.File like

type lr struct {
  fs.File
}

func (lr *r) Len() int {
    info, err := r.Stat()
    if err != nil {
        panic(err) // or ignore/log
    }
    return int(info.Size())
}

// LengthReaderFromFile returns a LengthReader from an fs.File
func LengthReaderFromFile(f fs.File) LengthReader {
    return &lr{f}
}

a.log.V(2).Info("info", "action", "set device to flash mode, takes a minute...", "step", "1/4")
err = a.setFlashMode(ctx)
if err != nil {
return fmt.Errorf("failed in step 1/4 - set device to flash mode: " + err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use errors.Wrap()? That would allow callers to use errors.Is(). Same for the other steps in this file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion here, as of now the file size is required for the multipart upload. I've created a separate issue to follow up on the LengthReader interface #261 (comment)

Fixed up errors Wrap in aa25390

providers/redfish/inventory.go Show resolved Hide resolved
Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, needs a rebase

…stallVerifier interface methods

- use context for all requests
- implement various helper methods for inventory, firmware updates
- split up firmware install, status methods
- add tests
… FirmwareInstallUnknown

this is so that the caller is aware that the BMC is not aware of the
component version and can decide if it wants to power cycle or take
other actions.

instead of assuming the device needs a powercycle
…payload

this is an attempt to have the BMC preserve the User, Network BMC
configuration after a flash
…eset

error returned when the install status lookup fails
Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great! Just a few minor changes

examples/v1/firmware/firmware.go Outdated Show resolved Hide resolved
examples/v1/firmware/firmware.go Outdated Show resolved Hide resolved
examples/v1/firmware/firmware.go Outdated Show resolved Hide resolved
examples/v1/firmware/firmware.go Outdated Show resolved Hide resolved
providers/asrockrack/firmware.go Outdated Show resolved Hide resolved
providers/asrockrack/firmware.go Show resolved Hide resolved
@joelrebel joelrebel force-pushed the inventory-firmware branch from 3c070f6 to ca6978d Compare April 26, 2022 14:52
@codecov
Copy link

codecov bot commented Apr 26, 2022

Codecov Report

Merging #261 (eb3610c) into master (2af4651) will increase coverage by 0.21%.
The diff coverage is 37.41%.

@@            Coverage Diff             @@
##           master     #261      +/-   ##
==========================================
+ Coverage   23.73%   23.94%   +0.21%     
==========================================
  Files          59       70      +11     
  Lines       10276    11425    +1149     
==========================================
+ Hits         2439     2736     +297     
- Misses       7300     8094     +794     
- Partials      537      595      +58     
Impacted Files Coverage Δ
client.go 0.00% <0.00%> (ø)
providers/asrockrack/power.go 0.00% <0.00%> (ø)
providers/redfish/inventory_collect.go 0.00% <0.00%> (ø)
providers/redfish/redfish.go 7.69% <8.33%> (ø)
providers/redfish/inventory.go 8.55% <8.55%> (ø)
providers/asrockrack/firmware.go 10.18% <10.18%> (ø)
providers/redfish/firmware.go 43.44% <43.44%> (ø)
providers/asrockrack/asrockrack.go 44.89% <57.14%> (+12.78%) ⬆️
providers/asrockrack/helpers.go 47.58% <63.88%> (+1.95%) ⬆️
providers/redfish/tasks.go 69.86% <69.86%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0cb1bdd...eb3610c. Read the comment docs.

- moves the optional component parameter at the end
- providers/asrockrack/firmware: wrap FirmwareInstall errors
@joelrebel joelrebel force-pushed the inventory-firmware branch from ca6978d to 04ed8e8 Compare April 26, 2022 15:28
@joelrebel joelrebel force-pushed the inventory-firmware branch from 04ed8e8 to 92f6fc0 Compare April 26, 2022 15:37
@joelrebel
Copy link
Member Author

rebased on master and squashed a few similar commits

@joelrebel joelrebel requested a review from micahhausler April 26, 2022 15:44
Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, no blocking changes

examples/v1/inventory/inventory.go Outdated Show resolved Hide resolved
providers/asrockrack/asrockrack.go Outdated Show resolved Hide resolved
@joelrebel joelrebel merged commit f660df4 into master Apr 27, 2022
@joelrebel joelrebel deleted the inventory-firmware branch July 26, 2022 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants